package org.itboys.basetemplate.service;

import java.util.List;

import javax.annotation.Resource;

import org.itboys.basetemplate.entity.ScoreDetail;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseService;
import org.springframework.stereotype.Service;

/**
 *	我的收藏
 */
@Service
public class ScoreDetailService extends BaseService<ScoreDetail, Long>{

	private static final long serialVersionUID = 1L;
	
	@Resource(name = "memberDS")
	private MongoDataSource ds;
	
	@Override
	protected MongoDataSource getMongoDataSource() {
		return ds;
	}
	
	/**
	 * 获取会员积分余额
	 * @param memberId
	 * @return
	 */
	public Double getCountByMemberId(Long memberId) {
		List<ScoreDetail> list = this.findByField("memberId", memberId);
		Double amount = 0.0;
		for (ScoreDetail score : list) {
			amount += Double.valueOf(score.getAmount());
		}
		return amount;
	}
}
